*&---------------------------------------------------------------------*
*& 包含               ZFIU019_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_INIT_SCREEN
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_INIT_SCREEN .

  CLEAR:
   GV_ERROR,
   ZFIT078_HEAD,
   ZFIT079_HEAD,
   ZFIT079_ITEM.

  REFRESH:
*    S_LIFNR[],
*    S_BUKRS[],
    S_EBELN[],
    S_EBELP[],
    S_AEDAT[],
    GT_EXTAB_BTN[],
    GT_ALV[].

  EKKO-BSTYP = 'F'."采购订单类别

  IF GV_JSDDH IS INITIAL.
    GV_MODE = GC_MODE_CHANGE.

    ZFIT079_HEAD-JSDZT = GC_JSDZT_DRAFT. "草稿
    ZFIT079_HEAD-JSDLX = GC_JSDLX_PO. "基于PO
    ZFIT079_HEAD-VORGANG = GC_YWCL_INV. "发票

    ZFIT079_HEAD-BUKRS = 'CN10'.
    SELECT SINGLE
      BUTXT
      INTO ZFIT079_HEAD-ZGFMC
      FROM T001
     WHERE BUKRS = ZFIT079_HEAD-BUKRS.

    IF RD_GUONEI IS NOT INITIAL.
      ZFIT079_HEAD-ZYWLX = GC_ZYWLX_DOMESTIC. "国内发票
      ZFIT079_HEAD-WAERS = GC_WAERS_CNY.

*      S_AEDAT-HIGH = SY-DATUM.
*      S_AEDAT-LOW = SY-DATUM - 30.
*      APPEND S_AEDAT.
    ENDIF.

    IF RD_GUOWAI IS NOT INITIAL.
      ZFIT079_HEAD-ZYWLX = GC_ZYWLX_FOREIGN. "国外发票
      ZFIT079_HEAD-ZKPSJ = SY-DATUM.
      ZFIT079_HEAD-ZFPHM = 'GW' && SY-DATUM && SY-UZEIT.

*      S_AEDAT-HIGH = SY-DATUM.
*      S_AEDAT-LOW = SY-DATUM - 30.
*      APPEND S_AEDAT.
    ENDIF.

    IF RD_JISHOU IS NOT INITIAL.
      ZFIT079_HEAD-ZYWLX = GC_ZYWLX_CONSIGNMENT. "寄售发票
      CLEAR:ZFIT079_HEAD-VORGANG.
    ENDIF.
  ELSE.

    GV_MODE = GC_MODE_DISPLAY.

    PERFORM FRM_GET_FPJSD_DATA USING GV_JSDDH."获取发票结算单数据

*    IF ZFIT079_HEAD-JSDLX = GC_JSDLX_PO AND ZFIT079_HEAD-ZYWLX <> GC_ZYWLX_CONSIGNMENT.
*      IF S_AEDAT[] IS INITIAL.
*        S_AEDAT-HIGH = SY-DATUM.
*        S_AEDAT-LOW = SY-DATUM - 30.
*        APPEND S_AEDAT.
*      ENDIF.
*    ENDIF.

  ENDIF.

  CASE ZFIT079_HEAD-JSDLX.
    WHEN '01'."基于PO
      GV_SUBSCREEN_9000 = '9001'.
    WHEN '02'. "无PO
      IF GV_MODE = GC_MODE_CHANGE.
        IF GT_ALV[] IS INITIAL.
          DO 10 TIMES.
            APPEND INITIAL LINE TO GT_ALV.
          ENDDO.
        ENDIF.
      ENDIF.

      GV_SUBSCREEN_9000 = '9009'.
    WHEN OTHERS.
  ENDCASE.

  CALL SCREEN 9000.

ENDFORM.


FORM FORM_ALV_DISPLAY_PO.
  IF GR_ALVGRID IS INITIAL.
    CREATE OBJECT GR_CONTAINER
      EXPORTING
        CONTAINER_NAME              = GC_CUSTOM_CONTROL_NAME
      EXCEPTIONS
        CNTL_ERROR                  = 1
        CNTL_SYSTEM_ERROR           = 2
        CREATE_ERROR                = 3
        LIFETIME_ERROR              = 4
        LIFETIME_DYNPRO_DYNPRO_LINK = 5
        OTHERS                      = 6.

    IF SY-SUBRC = 0.
      CREATE OBJECT GR_ALVGRID
        EXPORTING
          I_PARENT          = GR_CONTAINER
        EXCEPTIONS
          ERROR_CNTL_CREATE = 1
          ERROR_CNTL_INIT   = 2
          ERROR_CNTL_LINK   = 3
          ERROR_DP_CREATE   = 4
          OTHERS            = 5.

      PERFORM FORM_PREPARE_FIELD_CATALOG USING 'ZFIT079_ITEM' CHANGING GT_FIELDCAT.
      PERFORM FORM_PREPARE_LAYOUT CHANGING GS_LAYOUT .
      PERFORM FORM_TOOLBAR_EXCLUDING CHANGING GT_TOOLBAR_EXCLUDING.

      PERFORM FORM_SET_DRDN_TABLE USING '1' CHANGING GR_ALVGRID. "税码下拉列表

      CREATE OBJECT GR_EVENT_RECEIVER.
      SET HANDLER GR_EVENT_RECEIVER->HANDLE_DOUBLE_CLICK FOR GR_ALVGRID.
      SET HANDLER GR_EVENT_RECEIVER->HANDLE_DATA_CHANGED FOR GR_ALVGRID.
      SET HANDLER GR_EVENT_RECEIVER->HANDLE_HOTSPOT_CLICK FOR GR_ALVGRID.
      " SET HANDLER GR_EVENT_RECEIVER->HANDLE_MODIFY FOR GR_ALVGRID.

      GR_ALVGRID->REGISTER_EDIT_EVENT(
        EXPORTING
          I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED
        EXCEPTIONS
          ERROR      = 1
          OTHERS     = 2 ).

      CALL METHOD GR_ALVGRID->SET_TABLE_FOR_FIRST_DISPLAY
        EXPORTING
          IS_LAYOUT                     = GS_LAYOUT
          IT_TOOLBAR_EXCLUDING          = GT_TOOLBAR_EXCLUDING
        CHANGING
          IT_OUTTAB                     = GT_ALV[]
          IT_FIELDCATALOG               = GT_FIELDCAT
        EXCEPTIONS
          INVALID_PARAMETER_COMBINATION = 1
          PROGRAM_ERROR                 = 2
          TOO_MANY_LINES                = 3
          OTHERS                        = 4.
    ENDIF.

  ELSE .

    " GR_ALVGRID->CHECK_CHANGED_DATA( ).

    PERFORM FORM_PREPARE_FIELD_CATALOG USING 'ZFIT079_ITEM' CHANGING GT_FIELDCAT.
    PERFORM FORM_PREPARE_LAYOUT CHANGING GS_LAYOUT .
    PERFORM FORM_TOOLBAR_EXCLUDING CHANGING GT_TOOLBAR_EXCLUDING.

    PERFORM FORM_SET_DRDN_TABLE USING '1' CHANGING GR_ALVGRID. "税码下拉列表

    GR_ALVGRID->SET_FRONTEND_LAYOUT( GS_LAYOUT ).
    GR_ALVGRID->SET_FRONTEND_FIELDCATALOG( GT_FIELDCAT[] ).

    CALL METHOD GR_ALVGRID->REFRESH_TABLE_DISPLAY
      EXPORTING
        IS_STABLE = GS_STABLE
      EXCEPTIONS
        FINISHED  = 1
        OTHERS    = 2.

  ENDIF .

ENDFORM.

FORM FORM_ALV_DISPLAY_NPO.
  IF GR_ALVGRID_NPO IS INITIAL.
    CREATE OBJECT GR_CONTAINER_NPO
      EXPORTING
        CONTAINER_NAME              = GC_CUSTOM_CONTROL_NAME_NPO
      EXCEPTIONS
        CNTL_ERROR                  = 1
        CNTL_SYSTEM_ERROR           = 2
        CREATE_ERROR                = 3
        LIFETIME_ERROR              = 4
        LIFETIME_DYNPRO_DYNPRO_LINK = 5
        OTHERS                      = 6.

    IF SY-SUBRC = 0.
      CREATE OBJECT GR_ALVGRID_NPO
        EXPORTING
          I_PARENT          = GR_CONTAINER_NPO
        EXCEPTIONS
          ERROR_CNTL_CREATE = 1
          ERROR_CNTL_INIT   = 2
          ERROR_CNTL_LINK   = 3
          ERROR_DP_CREATE   = 4
          OTHERS            = 5.

      PERFORM FORM_PREPARE_FIELD_CATALOG USING 'ZFIT079_ITEM' CHANGING GT_FIELDCAT.
      PERFORM FORM_PREPARE_LAYOUT CHANGING GS_LAYOUT .
      PERFORM FORM_TOOLBAR_EXCLUDING CHANGING GT_TOOLBAR_EXCLUDING.

      PERFORM FORM_SET_DRDN_TABLE USING '2' CHANGING GR_ALVGRID_NPO. "借贷标识下拉列表
      PERFORM FORM_SET_DRDN_TABLE USING '3' CHANGING GR_ALVGRID_NPO. "税码下拉列表

      CREATE OBJECT GR_EVENT_RECEIVER.
      SET HANDLER GR_EVENT_RECEIVER->HANDLE_DOUBLE_CLICK FOR GR_ALVGRID_NPO.
      SET HANDLER GR_EVENT_RECEIVER->HANDLE_DATA_CHANGED FOR GR_ALVGRID_NPO.
      SET HANDLER GR_EVENT_RECEIVER->HANDLE_HOTSPOT_CLICK FOR GR_ALVGRID_NPO.
      "SET HANDLER G_EVENT_RECEIVER->HANDLE_MODIFY FOR GR_ALVGRID_200_EDIT.

      GR_ALVGRID_NPO->REGISTER_EDIT_EVENT(
        EXPORTING
          I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED
        EXCEPTIONS
          ERROR      = 1
          OTHERS     = 2 ).

      CALL METHOD GR_ALVGRID_NPO->SET_TABLE_FOR_FIRST_DISPLAY
        EXPORTING
          IS_LAYOUT                     = GS_LAYOUT
          IT_TOOLBAR_EXCLUDING          = GT_TOOLBAR_EXCLUDING
        CHANGING
          IT_OUTTAB                     = GT_ALV[]
          IT_FIELDCATALOG               = GT_FIELDCAT
        EXCEPTIONS
          INVALID_PARAMETER_COMBINATION = 1
          PROGRAM_ERROR                 = 2
          TOO_MANY_LINES                = 3
          OTHERS                        = 4.
    ENDIF.

  ELSE .

    "GR_ALVGRID->CHECK_CHANGED_DATA( ).

    PERFORM FORM_PREPARE_FIELD_CATALOG USING 'ZFIT079_ITEM' CHANGING GT_FIELDCAT.
    PERFORM FORM_PREPARE_LAYOUT CHANGING GS_LAYOUT .
    PERFORM FORM_TOOLBAR_EXCLUDING CHANGING GT_TOOLBAR_EXCLUDING.

    PERFORM FORM_SET_DRDN_TABLE USING '2' CHANGING GR_ALVGRID_NPO. "借贷标识下拉列表
    PERFORM FORM_SET_DRDN_TABLE USING '3' CHANGING GR_ALVGRID_NPO. "税码下拉列表

    GR_ALVGRID_NPO->SET_FRONTEND_LAYOUT( GS_LAYOUT ).
    GR_ALVGRID_NPO->SET_FRONTEND_FIELDCATALOG( GT_FIELDCAT[] ).

    CALL METHOD GR_ALVGRID_NPO->REFRESH_TABLE_DISPLAY
      EXPORTING
        IS_STABLE = GS_STABLE
      EXCEPTIONS
        FINISHED  = 1
        OTHERS    = 2.

  ENDIF .

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FORM_PREPARE_FIELD_CATALOG
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- GT_FIELDCAT_H
*&---------------------------------------------------------------------*
FORM FORM_PREPARE_FIELD_CATALOG USING IV_STRUC_NAME TYPE DD02L-TABNAME
      CHANGING CT_FIELDCAT  TYPE LVC_T_FCAT.

  REFRESH CT_FIELDCAT[].

  DATA:
    LV_POS  TYPE I,
    LS_FCAT TYPE LVC_S_FCAT.

  DEFINE SET_COLUMN.
    LV_POS = LV_POS + 1.
    CLEAR LS_FCAT.

    CASE &1.
      WHEN 'SELECT'.
         LS_FCAT-CHECKBOX = 'X'.
      WHEN 'MWSKZ'.
         LS_FCAT-DRDN_HNDL = '1'.
         LS_FCAT-DRDN_ALIAS = ABAP_TRUE.
      WHEN 'ERFME'.
         LS_FCAT-REF_TABLE = 'EKPO'.
         LS_FCAT-REF_FIELD = 'MEINS'.
      WHEN 'EBELN' or 'MBLNR'.
        LS_FCAT-HOTSPOT = 'X'.


      WHEN 'GL_HKONT'.
         LS_FCAT-REF_TABLE = 'ZFIT079_ITEM'.
         LS_FCAT-REF_FIELD = 'GL_HKONT'.
      WHEN 'GL_KOSTL'.
         LS_FCAT-REF_TABLE = 'ZFIT079_ITEM'.
         LS_FCAT-REF_FIELD = 'GL_KOSTL'.
      WHEN 'GL_SHKZG'.
         LS_FCAT-DRDN_HNDL = '2'.
         LS_FCAT-DRDN_ALIAS = ABAP_TRUE.
      WHEN 'GL_MWSKZ'.
         LS_FCAT-DRDN_HNDL = '3'.
         LS_FCAT-DRDN_ALIAS = ABAP_TRUE.
      WHEN OTHERS.
    ENDCASE.


    LS_FCAT-COL_POS = LV_POS.
    LS_FCAT-FIELDNAME = &1.
    LS_FCAT-TABNAME = 'GT_ALV'.
    LS_FCAT-SELTEXT = &2.
    LS_FCAT-COLTEXT = &2.

    IF GV_MODE = GC_MODE_CHANGE.
      LS_FCAT-EDIT      = &3.
    ELSE.
      LS_FCAT-EDIT      = SPACE.
    ENDIF.
    LS_FCAT-OUTPUTLEN = &4.
    APPEND LS_FCAT TO CT_FIELDCAT.
  END-OF-DEFINITION.

  IF ZFIT079_HEAD-JSDLX = GC_JSDLX_PO.
    SET_COLUMN 'SELECT'          TEXT-H00 'X'  ''.

    IF ZFIT079_HEAD-ZYWLX = GC_ZYWLX_CONSIGNMENT.
      SET_COLUMN 'MBLNR'           TEXT-H19 ''  ''.      "物料凭证编号
      SET_COLUMN 'MJAHR'           TEXT-H20 ''  ''.      "物料凭证的年份
      SET_COLUMN 'ZEILE'           TEXT-H21 ''  ''.      "物料凭证中的项目

      SET_COLUMN 'WERKS'           TEXT-H05 ''  ''.      "工厂
      SET_COLUMN 'WERKS_NAME'      TEXT-H06 ''  ''.      "工厂名称
      " SET_COLUMN 'CHARG'           TEXT-H07 ''  ''.      "批次
      SET_COLUMN 'MATNR'           TEXT-H08 ''  ''.      "物料
      SET_COLUMN 'TXZ01'           TEXT-H09 ''  ''.      "物料描述

      SET_COLUMN 'ERFMG'           TEXT-H12 ''  ''.      "收货数量
      SET_COLUMN 'ERFME'           TEXT-H13 ''  ''.      "单位
      SET_COLUMN 'WRBTR'           TEXT-H14 ''  ''.      "行项目不含税金额

      SET_COLUMN 'MWSKZ'           TEXT-H15 ''  ''.     "税码
      SET_COLUMN 'ZFPSL'           TEXT-H16 ''  ''.      "税率
      SET_COLUMN 'ZFPSE'           TEXT-H17 ''  ''.      "税额

    ELSE.
      SET_COLUMN 'EBELN'           TEXT-H01 ''  ''.      "PO
      SET_COLUMN 'EBELP'           TEXT-H02 ''  ''.      "PO行
      SET_COLUMN 'BSART'           TEXT-H03 ''  ''.      "PO类型
      SET_COLUMN 'BATXT'           TEXT-H04 ''  ''.      "PO类型描述
      SET_COLUMN 'WERKS'           TEXT-H05 ''  ''.      "工厂
      SET_COLUMN 'WERKS_NAME'      TEXT-H06 ''  ''.      "工厂名称
      SET_COLUMN 'CHARG'           TEXT-H07 ''  ''.      "批次
      SET_COLUMN 'MATNR'           TEXT-H08 ''  ''.      "物料
      SET_COLUMN 'TXZ01'           TEXT-H09 ''  ''.      "物料描述

*      SET_COLUMN 'MENGE'           TEXT-H10 ''  ''.      "PO数量
*      SET_COLUMN 'NETPR'           TEXT-H11 ''  ''.      "单价

      SET_COLUMN 'ERFMG'           TEXT-H12 'X'  ''.      "收货数量
      SET_COLUMN 'ERFME'           TEXT-H13 ''  ''.      "单位
      SET_COLUMN 'WRBTR'           TEXT-H14 'X'  ''.     "行项目不含税金额
      SET_COLUMN 'BEZNK'           '自动分摊金额'(H26) ''  ''.      "自动分摊的金额
      SET_COLUMN 'MWSKZ'           TEXT-H15 'X'  ''.     "税码
      SET_COLUMN 'ZFPSL'           TEXT-H16 ''  ''.      "税率
      SET_COLUMN 'ZFPSE'           TEXT-H17 ''  ''.      "税额
      SET_COLUMN 'WAERS'           TEXT-H18 ''  ''.      "货币

      SET_COLUMN 'MBLNR'           TEXT-H19 ''  ''.      "物料凭证编号
      SET_COLUMN 'MJAHR'           TEXT-H20 ''  ''.      "物料凭证的年份
      SET_COLUMN 'ZEILE'           TEXT-H21 ''  ''.      "物料凭证中的项目
      SET_COLUMN 'SHEET_NO'        TEXT-H24 ''  ''.
      SET_COLUMN 'COND_TYPE'       TEXT-H25 ''  ''.
      SET_COLUMN 'ZYSFPHM'         TEXT-H23 ''  ''.      "原始发票号码
    ENDIF.

  ELSEIF ZFIT079_HEAD-JSDLX = GC_JSDLX_NPO. "无PO
    SET_COLUMN 'GL_HKONT'          TEXT-H51 'X' ''.
    SET_COLUMN 'GL_HKONT_TXT'      TEXT-H52 '' '15'.
    SET_COLUMN 'GL_KOSTL'          TEXT-H53 'X' ''.
    SET_COLUMN 'GL_KOSTL_TXT'      TEXT-H54 '' '15'.
    "SET_COLUMN 'GL_ZOUNR'          TEXT-H55 'X' ''.
    SET_COLUMN 'GL_SGTXT'          TEXT-H56 'X' '20'.
    SET_COLUMN 'GL_SHKZG'          TEXT-H57 'X' '5'.
    SET_COLUMN 'GL_WRBTR'          TEXT-H58 'X' '20'.
    SET_COLUMN 'GL_MWSKZ'          TEXT-H59 'X' '5'.
    SET_COLUMN 'GL_ZFPSL'          TEXT-H60 '' ''.
    SET_COLUMN 'GL_ZFPSE'          TEXT-H61 '' ''.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FORM_PREPARE_LAYOUT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- GS_LAYOUT_H
*&---------------------------------------------------------------------*
FORM FORM_PREPARE_LAYOUT  CHANGING CS_LAYOUT TYPE LVC_S_LAYO.
  CS_LAYOUT-ZEBRA = 'X'.
  CS_LAYOUT-CWIDTH_OPT = 'X'.
  CS_LAYOUT-SEL_MODE = 'D'.

  CS_LAYOUT-SMALLTITLE = 'X' .
ENDFORM.

FORM FRM_GET_TAX_RATE USING
      IV_ALAND TYPE RF82T-LAND1
      IV_TAXCODE TYPE RF82T-MWSKZ
      CHANGING CV_TAXRATE TYPE ZDT_ZFPSL
               CV_EXIST_FLG TYPE C.

  DATA:
    LV_TXJCD TYPE RF82T-TXJCD,
    LT_FTAXP TYPE TABLE OF FTAXP WITH HEADER LINE.

  CLEAR:
    CV_EXIST_FLG,
    CV_TAXRATE.

  LV_TXJCD = 'TAX' && IV_ALAND.

  IF IV_TAXCODE IS NOT INITIAL.
    "取税率
    CALL FUNCTION 'GET_TAX_PERCENTAGE'
      EXPORTING
        ALAND   = IV_ALAND
        DATAB   = SY-DATUM
        MWSKZ   = IV_TAXCODE
        TXJCD   = LV_TXJCD
*       EXPORT  = ' '
      TABLES
        T_FTAXP = LT_FTAXP[].

    LOOP AT LT_FTAXP.
      CV_TAXRATE = LT_FTAXP-KBETR / 1000 * 100.
      CV_EXIST_FLG = 'X'.
    ENDLOOP.
  ENDIF.

ENDFORM.



FORM FRM_POPUP_TO_CONFIRM  USING    IV_POPUP_MSG
                       CHANGING CV_POPUP_YES.
  CLEAR CV_POPUP_YES.
  DATA LV_ANSWER.

  CALL FUNCTION 'POPUP_TO_CONFIRM'
    EXPORTING
      TITLEBAR              = IV_POPUP_MSG
      TEXT_QUESTION         = IV_POPUP_MSG
      DISPLAY_CANCEL_BUTTON = SPACE
    IMPORTING
      ANSWER                = LV_ANSWER
    EXCEPTIONS
      TEXT_NOT_FOUND        = 1
      OTHERS                = 2.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    RETURN.
  ENDIF.

  IF LV_ANSWER = '1'.
    CV_POPUP_YES = 'X'.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_ZFPHM_F4_VALUES
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> P_
*&---------------------------------------------------------------------*
FORM FRM_ZFPHM_F4_VALUES  USING   P_FIELD.
  DATA:
    LT_R_LIFNR      TYPE RANGE OF ZFIT078_HEAD-LIFNR WITH HEADER LINE,
    LT_R_BUKRS      TYPE RANGE OF ZFIT078_HEAD-BUKRS WITH HEADER LINE,
    LV_TABIX        TYPE I,
    LT_ZFIT078_HEAD TYPE TABLE OF ZFIT078_HEAD WITH HEADER LINE.

  IF ZFIT079_HEAD-ZYWLX = GC_ZYWLX_FOREIGN.
    MESSAGE '国外发票请手动录入发票号码'(M31) TYPE 'S'.
    RETURN.
  ENDIF.

  DATA:
    LS_DYNPRO_VALUES TYPE  DYNPREAD,
    LT_DYNPRO_VALUES TYPE  STANDARD TABLE OF DYNPREAD.

  DATA:
    LV_BUKRS TYPE ZFIT079_HEAD-BUKRS,
    LV_LIFNR TYPE ZFIT079_HEAD-LIFNR.

  LS_DYNPRO_VALUES-FIELDNAME = 'ZFIT079_HEAD-LIFNR'.
  APPEND LS_DYNPRO_VALUES TO LT_DYNPRO_VALUES  .
  LS_DYNPRO_VALUES-FIELDNAME = 'ZFIT079_HEAD-BUKRS'.
  APPEND LS_DYNPRO_VALUES TO LT_DYNPRO_VALUES  .

  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      DYNAME               = SY-REPID
      DYNUMB               = SY-DYNNR
      TRANSLATE_TO_UPPER   = 'X'
    TABLES
      DYNPFIELDS           = LT_DYNPRO_VALUES
    EXCEPTIONS
      INVALID_ABAPWORKAREA = 1
      INVALID_DYNPROFIELD  = 2
      INVALID_DYNPRONAME   = 3
      INVALID_DYNPRONUMMER = 4
      INVALID_REQUEST      = 5
      NO_FIELDDESCRIPTION  = 6
      INVALID_PARAMETER    = 7
      UNDEFIND_ERROR       = 8
      DOUBLE_CONVERSION    = 9
      STEPL_NOT_FOUND      = 10
      OTHERS               = 11.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CLEAR: LS_DYNPRO_VALUES.
  READ TABLE LT_DYNPRO_VALUES INTO LS_DYNPRO_VALUES WITH KEY FIELDNAME = 'ZFIT079_HEAD-BUKRS'.
  LV_BUKRS = LS_DYNPRO_VALUES-FIELDVALUE.

  CLEAR: LS_DYNPRO_VALUES.
  READ TABLE LT_DYNPRO_VALUES INTO LS_DYNPRO_VALUES WITH KEY FIELDNAME = 'ZFIT079_HEAD-LIFNR'.
  LV_LIFNR = LS_DYNPRO_VALUES-FIELDVALUE.
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      INPUT  = LV_LIFNR
    IMPORTING
      OUTPUT = LV_LIFNR.

  IF LV_LIFNR IS NOT INITIAL.
    CLEAR LT_R_LIFNR.
    LT_R_LIFNR-SIGN = 'I'.
    LT_R_LIFNR-OPTION = 'EQ'.
    LT_R_LIFNR-LOW = LV_LIFNR .
    APPEND LT_R_LIFNR.
  ENDIF.

  IF LV_BUKRS IS NOT INITIAL.
    CLEAR LT_R_BUKRS.
    LT_R_BUKRS-SIGN = 'I'.
    LT_R_BUKRS-OPTION = 'EQ'.
    LT_R_BUKRS-LOW = LV_BUKRS.
    APPEND LT_R_BUKRS.
  ENDIF.


  "获取发票数据
  SELECT *
    INTO TABLE LT_ZFIT078_HEAD
    FROM ZFIT078_HEAD
   WHERE LIFNR IN LT_R_LIFNR
     AND BUKRS IN LT_R_BUKRS.

  "排除结算单中已经存在的发票号码
  SELECT
    A~JSDDH,
    B~JSDHH,
    B~ZYSFPHM
    INTO TABLE @DATA(LT_JSD_EXIST)
    FROM ZFIT079_HEAD AS A
    JOIN ZFIT079_ITEM AS B
      ON A~JSDDH = B~JSDDH
     FOR ALL ENTRIES IN @LT_ZFIT078_HEAD
   WHERE B~ZYSFPHM = @LT_ZFIT078_HEAD-ZFPHM
     AND A~ZYWLX <> @GC_ZYWLX_FOREIGN
     AND A~JSDZT <> @GC_JSDZT_DEPRECATED
     AND A~JSDDH <> @ZFIT079_HEAD-JSDDH.

  SORT LT_JSD_EXIST BY ZYSFPHM.
  DELETE ADJACENT DUPLICATES FROM LT_JSD_EXIST COMPARING ZYSFPHM.

  LOOP AT LT_ZFIT078_HEAD.
    LV_TABIX = SY-TABIX.

    READ TABLE LT_JSD_EXIST TRANSPORTING NO FIELDS
      WITH KEY ZYSFPHM = LT_ZFIT078_HEAD-ZFPHM
      BINARY SEARCH.
    IF SY-SUBRC = 0 .
      DELETE LT_ZFIT078_HEAD INDEX LV_TABIX.
    ENDIF.
  ENDLOOP.

  SORT LT_ZFIT078_HEAD BY BUKRS LIFNR ZXFMC ZKPSJ ZFPHM.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      RETFIELD         = 'ZFPHM'
      DYNPPROG         = SY-REPID
      DYNPNR           = SY-DYNNR
      DYNPROFIELD      = P_FIELD
      VALUE_ORG        = 'S'
      CALLBACK_PROGRAM = SY-REPID
    TABLES
      VALUE_TAB        = LT_ZFIT078_HEAD
    EXCEPTIONS
      PARAMETER_ERROR  = 1
      NO_VALUES_FOUND  = 2
      OTHERS           = 3.
  IF SY-SUBRC <> 0.
*    MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.




*  DATA:
*   " LV_ZFPHM     TYPE ZFIT079_HEAD-ZFPHM,
*    LT_RET_TABLE TYPE TABLE OF DDSHRETVAL WITH HEADER LINE.
*
*  CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
*    EXPORTING
*      TABNAME           = 'ZFIT078_HEAD'
*      FIELDNAME         = 'ZFPHM'
*      DYNPPROG          = SY-REPID
*      DYNPNR            = SY-DYNNR
*      DYNPROFIELD       = P_FIELD
*    TABLES
*      RETURN_TAB        = LT_RET_TABLE[]
*    EXCEPTIONS
*      FIELD_NOT_FOUND   = 1
*      NO_HELP_FOR_FIELD = 2
*      INCONSISTENT_HELP = 3
*      NO_VALUES_FOUND   = 4
*      OTHERS            = 5.
*  IF SY-SUBRC <> 0.
**   Implement suitable error handling here
*  ENDIF.

*  READ TABLE LT_RET_TABLE INDEX 1.
*  IF LT_RET_TABLE-FIELDVAL IS NOT INITIAL.
*    LV_ZFPHM = LT_RET_TABLE-FIELDVAL.
*  ENDIF.
*
*  PERFORM FRM_GET_INV_DATA USING LV_ZFPHM.
ENDFORM.



FORM FRM_DYNP_UPDATE USING P_FIELDNAME  TYPE DYNFNAM
                         P_FIELDNAME2  TYPE DYNFNAM.

  DATA: LT_DYNPFIELDS TYPE TABLE OF DYNPREAD WITH HEADER LINE,
        LV_SYSTEPL    TYPE SYSTEPL.
  FIELD-SYMBOLS: <FS_FIELD> TYPE ANY.

  GET CURSOR LINE LV_SYSTEPL.
  LT_DYNPFIELDS-STEPL = LV_SYSTEPL.

  LT_DYNPFIELDS-FIELDNAME  = P_FIELDNAME.
  ASSIGN (P_FIELDNAME) TO <FS_FIELD>.
  IF SY-SUBRC EQ 0.
    LT_DYNPFIELDS-FIELDVALUE = <FS_FIELD>.
  ENDIF.
  APPEND LT_DYNPFIELDS.

  IF P_FIELDNAME2 IS NOT INITIAL.
    LT_DYNPFIELDS-FIELDNAME  = P_FIELDNAME2.
    ASSIGN (P_FIELDNAME2) TO <FS_FIELD>.
    IF SY-SUBRC EQ 0.
      LT_DYNPFIELDS-FIELDVALUE = <FS_FIELD>.
    ENDIF.
    APPEND LT_DYNPFIELDS.
  ENDIF.

  CALL FUNCTION 'DYNP_VALUES_UPDATE'
    EXPORTING
      DYNAME               = SY-REPID
      DYNUMB               = SY-DYNNR
    TABLES
      DYNPFIELDS           = LT_DYNPFIELDS
    EXCEPTIONS
      INVALID_ABAPWORKAREA = 1
      INVALID_DYNPROFIELD  = 2
      INVALID_DYNPRONAME   = 3
      INVALID_DYNPRONUMMER = 4
      INVALID_REQUEST      = 5
      NO_FIELDDESCRIPTION  = 6
      UNDEFIND_ERROR       = 7
      OTHERS               = 8.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_UPDATE_INV_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_GET_INV_DATA USING IV_ZFPHM TYPE ZFIT079_HEAD-ZFPHM.
  DATA:
    LV_MSG          TYPE STRING,
    LS_ZFIT079_HEAD TYPE ZFIT079_HEAD.

  CLEAR ZFIT078_HEAD.

  SELECT SINGLE *
    FROM ZFIT079_HEAD
    INTO LS_ZFIT079_HEAD
   WHERE ZFPHM = IV_ZFPHM
     AND ZYWLX <> GC_ZYWLX_FOREIGN
     AND JSDZT <> GC_JSDZT_DEPRECATED
     AND JSDDH <> ZFIT079_HEAD-JSDDH.
  IF SY-SUBRC = 0.
    LV_MSG = TEXT-M19.
    REPLACE ALL OCCURRENCES OF '&' IN LV_MSG WITH LS_ZFIT079_HEAD-JSDDH.
    MESSAGE LV_MSG TYPE 'E'.
    RETURN.
  ENDIF.

  CLEAR LS_ZFIT079_HEAD.
  LS_ZFIT079_HEAD = ZFIT079_HEAD.

  SELECT SINGLE *
    INTO ZFIT078_HEAD
    FROM ZFIT078_HEAD
   WHERE ZFPHM = IV_ZFPHM.
  IF SY-SUBRC = 0.
    IF ZFIT079_HEAD-ZYWLX = GC_ZYWLX_FOREIGN.
      MESSAGE '该发票为国内发票，不能用作国外发票结算单'(M22) TYPE 'E'.
      RETURN.
    ENDIF.

    "购方名称检查
    CONDENSE: ZFIT078_HEAD-ZGFMC.
    IF ZFIT078_HEAD-ZGFMC <> '华菱安赛乐米塔尔汽车板有限公司'.
      MESSAGE '该发票购方名称不正确，请检查'(M39) TYPE 'E'.
      RETURN.
    ENDIF.

    MOVE-CORRESPONDING ZFIT078_HEAD TO ZFIT079_HEAD.
    ZFIT079_HEAD-CRNAM = LS_ZFIT079_HEAD-CRNAM.
    ZFIT079_HEAD-CRDAT = LS_ZFIT079_HEAD-CRDAT.
    ZFIT079_HEAD-CRTIM = LS_ZFIT079_HEAD-CRTIM.

    IF ZFIT078_HEAD-INVOICE_STATUS CS '红冲'.
      ZFIT079_HEAD-VORGANG = GC_YWCL_SUBSC. "发票事务 后续贷记
    ELSE.
      ZFIT079_HEAD-VORGANG = GC_YWCL_INV. "发票事务 发票
    ENDIF.

    IF ZFIT078_HEAD-INVOICE_LINE CS '17'."海关缴款书
      ZFIT079_HEAD-VORGANG = GC_YWCL_SUBSD. "发票事务 后续借记
    ENDIF.

    ZFIT079_HEAD-WAERS = GC_WAERS_CNY.

  ELSE.

    IF ZFIT079_HEAD-ZYWLX <> GC_ZYWLX_FOREIGN.
      CLEAR:
        ZFIT079_HEAD-ZFPLX,
        ZFIT079_HEAD-ZKPSJ,
        ZFIT079_HEAD-BUKRS,
        ZFIT079_HEAD-ZGFMC,
        ZFIT079_HEAD-LIFNR,
        ZFIT079_HEAD-ZXFMC,
        ZFIT079_HEAD-ZHSJE,
        ZFIT079_HEAD-ZHJSE,
        ZFIT079_HEAD-ZBHSJE,
        ZFIT079_HEAD-WAERS.
    ENDIF.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_LIFNR_CHANGE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_LIFNR_CHANGE .
  SELECT SINGLE
    NAME1
    INTO ZFIT079_HEAD-ZXFMC
    FROM LFA1
   WHERE LIFNR = ZFIT079_HEAD-LIFNR.
  IF SY-SUBRC <> 0.
    CLEAR ZFIT079_HEAD-ZXFMC.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GENERATE_JSDDH
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> ZFIT079_HEAD_ZYWLX
*&      <-- ZFIT079_HEAD_JSDDH
*&---------------------------------------------------------------------*
FORM FRM_GENERATE_JSDDH  USING    IV_ZYWLX TYPE ZFIT079_HEAD-ZYWLX
                         CHANGING CV_JSDDH TYPE ZFIT079_HEAD-JSDDH.

  DATA:
    LV_NR_RANGE_NR TYPE INRI-NRRANGENR.

  CASE IV_ZYWLX.
    WHEN GC_ZYWLX_DOMESTIC. "国内发票
      LV_NR_RANGE_NR = '10'.
    WHEN GC_ZYWLX_FOREIGN. "国外发票
      LV_NR_RANGE_NR = '10'. "'20'.
    WHEN GC_ZYWLX_CONSIGNMENT. "寄售
      LV_NR_RANGE_NR = '10'.  "'30'.
    WHEN OTHERS.
  ENDCASE.

  CLEAR CV_JSDDH.

* Get the number range
  CALL FUNCTION 'NUMBER_RANGE_ENQUEUE'
    EXPORTING
      OBJECT           = 'ZFI_FPJSD'
    EXCEPTIONS
      FOREIGN_LOCK     = 1
      OBJECT_NOT_FOUND = 2
      SYSTEM_FAILURE   = 3
      OTHERS           = 4.


  CALL FUNCTION 'NUMBER_GET_NEXT'
    EXPORTING
      NR_RANGE_NR             = LV_NR_RANGE_NR
      OBJECT                  = 'ZFI_FPJSD'
*     QUANTITY                = '1'
*     SUBOBJECT               = ' '
*     TOYEAR                  = '0000'
*     IGNORE_BUFFER           = ' '
    IMPORTING
      NUMBER                  = CV_JSDDH
*     QUANTITY                =
*     RETURNCODE              =
    EXCEPTIONS
      INTERVAL_NOT_FOUND      = 1
      NUMBER_RANGE_NOT_INTERN = 2
      OBJECT_NOT_FOUND        = 3
      QUANTITY_IS_0           = 4
      QUANTITY_IS_NOT_1       = 5
      INTERVAL_OVERFLOW       = 6
      BUFFER_OVERFLOW         = 7
      OTHERS                  = 8.

  CALL FUNCTION 'NUMBER_RANGE_DEQUEUE'
    EXPORTING
      OBJECT           = 'ZFI_FPJSD'
    EXCEPTIONS
      OBJECT_NOT_FOUND = 1
      OTHERS           = 2.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM__CHG_SCREEN_ATTRIBUTE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_CHG_SCREEN_ATTRIBUTE .
  LOOP AT SCREEN.
    IF GV_MODE = GC_MODE_DISPLAY.
      SCREEN-INPUT = 0.
    ENDIF.

    IF ZFIT079_HEAD-ZYWLX = GC_ZYWLX_CONSIGNMENT.
      IF SCREEN-NAME CS 'S_BSART' OR SCREEN-NAME CS 'S_EKGRP' OR
        SCREEN-NAME CS 'S_EBELN' OR SCREEN-NAME CS 'S_EBELP' OR
        SCREEN-NAME CS 'S_CHARG' OR SCREEN-NAME CS 'S_ERNAM' OR
        SCREEN-NAME CS 'S_AEDAT' OR SCREEN-NAME CS 'S_LICHA' OR
        SCREEN-NAME CS 'P_XWARE' OR SCREEN-NAME CS 'P_XBNKYF' OR
        SCREEN-NAME CS 'P_XBNKQT' OR SCREEN-NAME CS 'P_ZBL' OR
        SCREEN-NAME CS 'ZFIT079_HEAD-SGTXT' OR SCREEN-NAME CS 'ZFIT079_HEAD-VORGANG'.

        SCREEN-ACTIVE = 0. "隐藏

      ELSEIF SCREEN-NAME = 'ZFIT079_HEAD-JSDLX'.
        SCREEN-INPUT = 0. "不可编辑

      ENDIF.
    ENDIF.

    IF ZFIT079_HEAD-ZYWLX <> GC_ZYWLX_CONSIGNMENT.
      IF SCREEN-NAME CS 'S_BELNR'.
        SCREEN-ACTIVE = 0. "隐藏
      ENDIF.
    ENDIF.

    IF GV_MODE = GC_MODE_CHANGE AND ZFIT079_HEAD-ZYWLX = GC_ZYWLX_FOREIGN."国外发票
      IF SCREEN-NAME = 'ZFIT079_HEAD-ZHSJE' OR SCREEN-NAME = 'ZFIT079_HEAD-ZHJSE'
        OR SCREEN-NAME = 'ZFIT079_HEAD-ZBHSJE' OR SCREEN-NAME = 'ZFIT079_HEAD-ZKPSJ'
        OR SCREEN-NAME = 'ZFIT079_HEAD-WAERS'.

        SCREEN-INPUT = 1. "可编辑
      ENDIF.
    ENDIF.

    IF ZFIT079_HEAD-ZPLCJ_FLG IS NOT INITIAL. "来自批量创建
      IF SCREEN-NAME = 'ZFIT079_HEAD-ZFPHM' OR SCREEN-NAME = 'BTN_FP_CLEAR' OR SCREEN-NAME = 'BTN_QUERY'.
        SCREEN-INPUT = 0. "不可编辑/不起作用
      ENDIF.
    ENDIF.

    MODIFY SCREEN.
  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FORM_TOOLBAR_EXCLUDING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- CT_TOOLBAR_EXCLUDING
*&---------------------------------------------------------------------*
FORM FORM_TOOLBAR_EXCLUDING  CHANGING CT_TOOLBAR_EXCLUDING TYPE UI_FUNCTIONS.

  DATA: LS_TOOLBAR_EXCLUDING TYPE UI_FUNC.

  REFRESH CT_TOOLBAR_EXCLUDING[].

  CLEAR: LS_TOOLBAR_EXCLUDING.
  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_AUF.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  CLEAR LS_TOOLBAR_EXCLUDING.
  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_BACK_CLASSIC.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  IF ZFIT079_HEAD-JSDLX = GC_JSDLX_PO.
    CLEAR LS_TOOLBAR_EXCLUDING.
    LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.
    APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
    CLEAR LS_TOOLBAR_EXCLUDING.

    LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.
    APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
    CLEAR LS_TOOLBAR_EXCLUDING.

    LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.
    APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
    CLEAR LS_TOOLBAR_EXCLUDING.

    LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.
    APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
    CLEAR LS_TOOLBAR_EXCLUDING.

    LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.
    APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
    CLEAR LS_TOOLBAR_EXCLUDING.
  ENDIF.


  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_PRINT.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

*  CLEAR LS_TOOLBAR_EXCLUDING.
*  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_AVERAGE.
*  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
*  CLEAR LS_TOOLBAR_EXCLUDING.
*
*  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_SUBTOT.
*  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
*  CLEAR LS_TOOLBAR_EXCLUDING.
*
*  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_MB_SUBTOT.
*  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
*  CLEAR LS_TOOLBAR_EXCLUDING.
*
*  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_MB_SUM.
*  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
*  CLEAR LS_TOOLBAR_EXCLUDING.
*
*  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_SUM.
*  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
*  CLEAR LS_TOOLBAR_EXCLUDING.

  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_VIEWS.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_MB_VIEW.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_REFRESH.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_CHECK.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_INFO.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_PRINT_BACK.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.


  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_PRINT_PREV.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_GRAPH.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

  LS_TOOLBAR_EXCLUDING = CL_GUI_ALV_GRID=>MC_FC_VIEW_EXCEL.
  APPEND LS_TOOLBAR_EXCLUDING TO CT_TOOLBAR_EXCLUDING.
  CLEAR LS_TOOLBAR_EXCLUDING.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_ADD_PROTOCOL_ENTRY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> P_
*&      --> P_
*&      --> P_
*&      --> LS_LVC_MODI_FIELDNAME
*&      --> LV_MSG
*&      --> P_
*&      --> LS_LVC_MODI_ROW_ID
*&      --> ER_DATA_CHANGED
*&---------------------------------------------------------------------*
FORM FRM_ADD_PROTOCOL_ENTRY  USING    VALUE(PV_MSGID)
                                    VALUE(PV_MSGTY)
                                    VALUE(PV_MSGNO)
                                    VALUE(PV_FIELDNAME)
                                    VALUE(PV_MSGV1)
                                    VALUE(PV_MSGV2)
                                    PV_ROW_ID
                                    PO_DATA_CHANGED TYPE REF TO
                                    CL_ALV_CHANGED_DATA_PROTOCOL.

  CALL METHOD PO_DATA_CHANGED->ADD_PROTOCOL_ENTRY
    EXPORTING
      I_MSGID     = PV_MSGID
      I_MSGTY     = PV_MSGTY
      I_MSGNO     = PV_MSGNO
      I_FIELDNAME = PV_FIELDNAME
      I_ROW_ID    = PV_ROW_ID
      I_MSGV1     = PV_MSGV1
      I_MSGV2     = PV_MSGV2.

ENDFORM.                    "                   " F_ADD_PROTOCOL_ENTRY
*&---------------------------------------------------------------------*
*& Form FORM_SET_DRDN_TABLE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FORM_SET_DRDN_TABLE USING IV_DRDN_HNDL TYPE LVC_S_DROP-HANDLE
      CHANGING CR_ALV_GRID TYPE REF TO CL_GUI_ALV_GRID.

  DATA: LT_DROPDOWN TYPE LVC_T_DROP,
        LS_DROPDOWN TYPE LVC_S_DROP.

  DATA: LT_DRAL TYPE LVC_T_DRAL,                            "#EC NEEDED
        LS_DRAL TYPE LVC_S_DRAL.                            "#EC NEEDED

  CASE IV_DRDN_HNDL.
    WHEN '2'.  "借贷标识
      CLEAR LS_DROPDOWN.
      LS_DROPDOWN-HANDLE = IV_DRDN_HNDL.
      LS_DROPDOWN-VALUE = 'S'.
      APPEND LS_DROPDOWN TO LT_DROPDOWN.

      CLEAR LS_DROPDOWN.
      LS_DROPDOWN-HANDLE = IV_DRDN_HNDL.
      LS_DROPDOWN-VALUE = 'H'.
      APPEND LS_DROPDOWN TO LT_DROPDOWN.

      CLEAR LS_DRAL.
      LS_DRAL-HANDLE = IV_DRDN_HNDL.
      LS_DRAL-INT_VALUE = 'S'.
      CONCATENATE LS_DRAL-INT_VALUE  TEXT-T02
        INTO LS_DRAL-VALUE SEPARATED BY SPACE .
      APPEND LS_DRAL TO LT_DRAL.

      CLEAR LS_DRAL.
      LS_DRAL-HANDLE = IV_DRDN_HNDL.
      LS_DRAL-INT_VALUE = 'H'.
      CONCATENATE LS_DRAL-INT_VALUE  TEXT-T03
        INTO LS_DRAL-VALUE SEPARATED BY SPACE .
      APPEND LS_DRAL TO LT_DRAL.

    WHEN '1' OR '3'. "税码
      "根据税率取税码
      SELECT
         KONP~MWSK1,
         KONP~KBETR,
         T007S~TEXT1
         INTO TABLE @DATA(LT_T007)
         FROM KONP
         JOIN A003
           ON KONP~KNUMH = A003~KNUMH
          AND KONP~KAPPL = A003~KAPPL
          AND KONP~KSCHL = A003~KSCHL
          AND KONP~MWSK1 = A003~MWSKZ
         JOIN T007S
           ON KONP~MWSK1 = T007S~MWSKZ
        WHERE KONP~KAPPL = 'TX'
          AND KONP~KSCHL = 'MWVS'
          AND T007S~KALSM = 'TAXCN'
          AND T007S~SPRAS = '1'
          AND A003~ALAND = 'CN'.

      SORT LT_T007 BY MWSK1.
      LOOP AT LT_T007 INTO DATA(LS_T007).
        CLEAR LS_DROPDOWN.
        LS_DROPDOWN-HANDLE = IV_DRDN_HNDL.
        LS_DROPDOWN-VALUE = LS_T007-MWSK1.
        APPEND LS_DROPDOWN TO LT_DROPDOWN.

        CLEAR LS_DRAL.
        LS_DRAL-HANDLE = IV_DRDN_HNDL.
        LS_DRAL-INT_VALUE = LS_T007-MWSK1.
        CONCATENATE LS_T007-MWSK1 LS_T007-TEXT1 INTO
          LS_DRAL-VALUE SEPARATED BY SPACE.
        APPEND LS_DRAL TO LT_DRAL.
      ENDLOOP.
    WHEN OTHERS.
  ENDCASE.

  CR_ALV_GRID->SET_DROP_DOWN_TABLE(
    IT_DROP_DOWN = LT_DROPDOWN ).

  CR_ALV_GRID->SET_DROP_DOWN_TABLE(
    IT_DROP_DOWN_ALIAS = LT_DRAL ).

ENDFORM.

FORM FRM_READ_DOMAIN_TEXT  USING    IV_KEY
                                IV_DOMNAME
                       CHANGING CV_TEXT.
  DATA:
    LS_TAB TYPE DD07V,
    LT_TAB TYPE STANDARD TABLE OF DD07V.

  CLEAR CV_TEXT.

  CALL FUNCTION 'DD_DOMVALUES_GET'
    EXPORTING
      DOMNAME        = IV_DOMNAME
      TEXT           = 'X'
    TABLES
      DD07V_TAB      = LT_TAB
    EXCEPTIONS
      WRONG_TEXTFLAG = 1
      OTHERS         = 2.

  IF SY-SUBRC <> 0.
    RETURN.
  ENDIF.

  LOOP AT LT_TAB INTO LS_TAB.
    IF LS_TAB-DOMVALUE_L = IV_KEY.
      CV_TEXT = LS_TAB-DDTEXT.
      EXIT.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " READ_DOMAIN_TEXT
*&---------------------------------------------------------------------*
*& Form FRM_ADD_CHARG
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> S_CHARG
*&      --> S_LICHA
*&      <-- LT_R_CHARG
*&---------------------------------------------------------------------*
FORM FRM_ADD_CHARG  USING    IT_R_CHARG TYPE TT_R_CHARG
                             IT_R_LICHA  TYPE TT_R_LICHA
                    CHANGING CT_R_CHARG TYPE TT_R_CHARG.


  DATA:
    WT_MCH1    LIKE MCH1 OCCURS 0 WITH HEADER LINE,
    LV_ATINN   LIKE CABN-ATINN,
    LS_R_CHARG TYPE LINE OF TT_R_CHARG.

  IF IT_R_CHARG[] IS NOT INITIAL.
    SELECT * INTO TABLE WT_MCH1 FROM MCH1
      WHERE CHARG IN IT_R_CHARG.
  ENDIF.

  IF IT_R_LICHA[] IS NOT INITIAL.
    SELECT * APPENDING TABLE WT_MCH1 FROM MCH1                                "从MCH1里根据供应商批次获取
      WHERE LICHA IN IT_R_LICHA.

    SELECT SINGLE ATINN INTO LV_ATINN FROM CABN
      WHERE ATNAM = 'V_BATCH'.

    SELECT *
      APPENDING CORRESPONDING FIELDS OF TABLE WT_MCH1
      FROM MCH1        "从MCH1里根据批次特性的供应商批次获取
      INNER JOIN AUSP ON AUSP~OBJEK = MCH1~CUOBJ_BM
      WHERE KLART = '023'
        AND ATINN = LV_ATINN
        AND ATWRT IN IT_R_LICHA.
    IF WT_MCH1[] IS INITIAL.
      WT_MCH1-CHARG = '0000000000'.                                          "如果MCH1的批次不存在，但是又有供应商批次要求，则设置一个不存在的批次
      APPEND WT_MCH1.
    ENDIF.
  ENDIF.

  CHECK WT_MCH1[] IS NOT INITIAL.
  SORT WT_MCH1 BY CHARG MATNR.
  DELETE ADJACENT DUPLICATES FROM WT_MCH1 COMPARING CHARG MATNR.


  REFRESH  CT_R_CHARG[].
  LOOP AT WT_MCH1.
    CLEAR LS_R_CHARG.
    LS_R_CHARG-SIGN = 'I'.
    LS_R_CHARG-OPTION = 'EQ'.
    LS_R_CHARG-LOW = WT_MCH1-CHARG.
    APPEND LS_R_CHARG TO CT_R_CHARG.
  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GOS_MANAGE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_GOS_MANAGE .
  DATA:
    LS_OBJECT TYPE SIBFLPORB,
    LV_MODE   TYPE CHAR1.

  IF GV_MODE = GC_MODE_CHANGE.
    LV_MODE = 'E'.
  ELSE.
    LV_MODE = 'D'.
  ENDIF.

  LS_OBJECT-INSTID = ZFIT079_HEAD-JSDDH.
  LS_OBJECT-TYPEID = 'ZZFI_FPJSD'.
  LS_OBJECT-CATID = 'BO'.

  CALL FUNCTION 'GOS_ATTACHMENT_LIST_POPUP'
    EXPORTING
      IS_OBJECT      = LS_OBJECT
*     IP_CHECK_ARL   = 'X'
      IP_CHECK_BDS   = ''
      IP_NOTES       = ''
      IP_ATTACHMENTS = ''
      IP_URLS        = ''
      IP_MODE        = LV_MODE
* IMPORTING
*     EP_SAVE_REQUEST       =
* TABLES
*     IT_OBJECTS     =
    .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_BUKRS_CHANGE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_BUKRS_CHANGE .
  SELECT SINGLE
    BUTXT
    INTO ZFIT079_HEAD-ZGFMC
    FROM T001
   WHERE BUKRS = ZFIT079_HEAD-BUKRS.

  IF SY-SUBRC <> 0.
    CLEAR ZFIT079_HEAD-ZGFMC.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CLR_INV_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_CLR_INV_DATA .
  CLEAR ZFIT078_HEAD.

  CLEAR:
      ZFIT079_HEAD-ZFPHM,
      ZFIT079_HEAD-ZFPLX,
      ZFIT079_HEAD-ZKPSJ,
*      ZFIT079_HEAD-BUKRS,
*      ZFIT079_HEAD-ZGFMC,
      ZFIT079_HEAD-LIFNR,
      ZFIT079_HEAD-ZXFMC,
      ZFIT079_HEAD-ZHSJE,
      ZFIT079_HEAD-ZHJSE,
      ZFIT079_HEAD-ZBHSJE,
      ZFIT079_HEAD-WAERS.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_LOCK_JSDDH
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> ZFIT079_HEAD_JSDDH
*&---------------------------------------------------------------------*
FORM FRM_LOCK_JSDDH  USING    IV_JSDDH TYPE ZFIT079_HEAD-JSDDH.

  CALL FUNCTION 'ENQUEUE_EZFIT079_HEAD'
    EXPORTING
      JSDDH          = IV_JSDDH
    EXCEPTIONS
      FOREIGN_LOCK   = 1
      SYSTEM_FAILURE = 2
      OTHERS         = 3.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM.


FORM FRM_UNLOCK_JSDDH  USING    IV_JSDDH TYPE ZFIT079_HEAD-JSDDH.

  CALL FUNCTION 'DEQUEUE_EZFIT079_HEAD'
    EXPORTING
*     MODE_ZFIT079_HEAD       = 'E'
*     MANDT = SY-MANDT
      JSDDH = IV_JSDDH.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SELECT_ALL_OR_CLEAR
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> P_
*&---------------------------------------------------------------------*
FORM FRM_SELECT_ALL_OR_CLEAR  USING IV_SEL.
  LOOP AT GT_ALV.
    GT_ALV-SELECT = IV_SEL.
    MODIFY GT_ALV.
  ENDLOOP.
ENDFORM.
